import util.lib as lib
import pandas as pd

from daily import get_daily_share_file_name as get_daily_share_file_name


def job():
    data = pd.read_excel(lib.data_path + 'operation.xlsx',index_col=0 ,sheet_name=None)

    df_vol = data["两市成交额"]

    #df_north = data["北向"]

    df = pd.DataFrame()

    # index_col=0 将第一列设置为索引
    indexs = ["上证指数","沪深300","创业板","科创50","中证500","中证1000","中证全指"]
    for index in indexs:
        tmp_df = pd.read_excel(get_daily_share_file_name(index),index_col=0)
        df[index] = tmp_df['pct'][-2000:]
        print(index)

    #df["north_money"] = df_north["north_money"]
    df["成交额"] = df_vol["成交额"]
    df["中证全指成交额"] = df_vol["中证全指"]

    de_sum_df = lib.lib_get_de_sum_data()
    
    count_df = de_sum_df[["date","de_sum"]].groupby("date").count()
    count_df.rename(columns={"de_sum":"de_sum_count"}, inplace=True)

    next_pct_mean_df = de_sum_df[["date","next_pct"]].groupby("date").mean()
    next_pct_mean_df.rename(columns={"next_pct":"next_pct_mean"}, inplace=True)
    next_pct_mean_df["next_pct_mean"] = round(next_pct_mean_df["next_pct_mean"],2)

    next_pct_mean_df["de_sum_count"] = count_df["de_sum_count"]


    df = pd.merge(df, next_pct_mean_df,left_index=True, right_index=True , how="left")

    writer = pd.ExcelWriter('data/index_sta.xlsx')
    df.to_excel(writer, 'index_sta')
    writer.save()


if __name__ == '__main__':
    job()